package StudyCode.summary.mycollection;

import java.util.Iterator;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReturnsTheGivenIteratorLastElementOrNull {
	public static <T> T lastOrNull(Iterator<T> iterator) {
		T result = null;
		while (iterator.hasNext()) {
			result = iterator.next();
		}
		return result;
	}


	public static <T> T lastOrNull(Iterable<T> iterable) {
		return lastOrNull(iterable.iterator());
	}
}
